package com.workcell.workdata.xthings.controller;

import cn.hutool.core.lang.Assert;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.workcell.workdata.common.core.util.R;
import com.workcell.workdata.common.security.annotation.Inner;
import com.workcell.workdata.xthings.dto.DeviceServiceCallLogVo;
import com.workcell.workdata.xthings.entity.DeviceServiceCallLog;
import com.workcell.workdata.xthings.service.DeviceServiceCallLogService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

@RestController
@RequiredArgsConstructor
@RequestMapping("/deviceServiceCallLog" )
@Api(value = "deviceServiceCallLog", tags = "服务调用")
public class DeviceServiceCallLogController {

	private final DeviceServiceCallLogService deviceServiceCallLogService;

	/**
	 * 新添/修改日志
	 * @param deviceServiceCallLog
	 * @return
	 */
	@Inner
	@ApiOperation(value = "新添/修改日志", notes = "新添/修改日志")
	@ResponseBody
	@PostMapping
	public R saveOrUpdate(@RequestBody DeviceServiceCallLog deviceServiceCallLog) {
		deviceServiceCallLogService.saveOrUpdate(deviceServiceCallLog);
		return R.ok(deviceServiceCallLog);
	}

	@ApiOperation(value = "模糊分页查询", notes = "模糊分页查询")
	@GetMapping("/vaguePage")
	public R<Page<DeviceServiceCallLog>> vaguePage(DeviceServiceCallLogVo.SelectDataVo selectDataVo) {
		Assert.isTrue(ObjectUtil.isAllEmpty(selectDataVo.getStartTime(),selectDataVo.getEndTime()) || ObjectUtil.isAllNotEmpty(selectDataVo.getStartTime(),selectDataVo.getEndTime()),"请选择起止时间");
		return R.ok(deviceServiceCallLogService.vaguePage(selectDataVo));
	}

}
